import requests

import request
import re

index = 1


def image_list(url):
    if url is None:
        return
    if len(url) == 0:
        return
    html = request.request_data(url, None)
    if html == "-1":
        return
    rex = "https://mmbiz.qpic.cn.*?\""  # 正则表达
    try:
        pattern = re.compile(pattern=rex, flags=re.S)
        match = pattern.findall(html)
        for data in match:
            image = str(data).replace("\"", "")
            print(image)
            r = requests.get(image, headers=None, stream=True, timeout=10)
            print(r.status_code)  # 返回状态码
            if r.status_code == 200:
                global index
                type = r.headers.get("content-type")
                open("F:\\download\\python_download\\居儿图苑\\" + str(index) + "." + type.replace("image/", ""),
                     "wb").write(
                    r.content)
                index = index + 1
            del r
    except BaseException:
        print('BaseException')
